/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */

/**
 * @param {ListNode} headA
 * @param {ListNode} headB
 * @return {ListNode}
 */
 var getIntersectionNode = function(headA, headB) {
    if(!headA || !headB){
        return null;
    }
    let nodea=headA,nodeb=headB;
    while(nodea!=nodeb){
        nodeA=nodeA == null ? headB : nodeA.next;
        nodeB=nodeB == null ? headA : nodeB.next;
    }
    return nodea;
};